const express = require('express');
const router = express.Router();
const ReportController = require('../controllers/ReportController');
const authenticate = require('../middleware/auth');

/**
 * @swagger
 * tags:
 *   name: Reports
 *   description: 报表管理
 */

// All routes require authentication
router.use(authenticate);

/**
 * @swagger
 * /api/reports:
 *   post:
 *     summary: 生成新报表
 *     tags: [Reports]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - type
 *               - period_start
 *               - period_end
 *             properties:
 *               type:
 *                 type: string
 *                 enum: [summary, category, trend]
 *                 description: 报表类型
 *               period_start:
 *                 type: string
 *                 format: date
 *                 description: 开始日期 (YYYY-MM-DD)
 *               period_end:
 *                 type: string
 *                 format: date
 *                 description: 结束日期 (YYYY-MM-DD)
 *     responses:
 *       201:
 *         description: 报表生成成功
 *       400:
 *         description: 请求参数错误
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */
router.post('/', ReportController.generateReport);

/**
 * @swagger
 * /api/reports:
 *   get:
 *     summary: 获取用户报表列表
 *     tags: [Reports]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: query
 *         name: type
 *         schema:
 *           type: string
 *         description: 报表类型
 *     responses:
 *       200:
 *         description: 成功获取报表列表
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */
router.get('/', ReportController.getReports);

/**
 * @swagger
 * /api/reports/{id}:
 *   get:
 *     summary: 获取特定报表详情
 *     tags: [Reports]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 报表ID
 *     responses:
 *       200:
 *         description: 成功获取报表详情
 *       401:
 *         description: 未授权
 *       404:
 *         description: 报表未找到
 *       500:
 *         description: 服务器内部错误
 */
router.get('/:id', ReportController.getReportById);

/**
 * @swagger
 * /api/reports/{id}:
 *   delete:
 *     summary: 删除报表
 *     tags: [Reports]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 报表ID
 *     responses:
 *       200:
 *         description: 报表删除成功
 *       401:
 *         description: 未授权
 *       404:
 *         description: 报表未找到
 *       500:
 *         description: 服务器内部错误
 */
router.delete('/:id', ReportController.deleteReport);

module.exports = router;